<template>
    <div>
        <p>
            <a-button type="primary" v-if="showUpload" @click="handleUpload">上传{{ type }}</a-button>
        </p>
        <p v-for="item in gwfjList" :key="item.unid">
            <a-button type="link" @click="openFilesModal(item)">{{ item.bt }}</a-button>
        </p>
        <upload-group
        ref="roup"
        :relationUnid="relationUnid"
        :module-name="moduleName"
        :bookmark="bookmark"
        @reload="reload"
      ></upload-group>
      <GwfjFilesListModal ref="gwfjfilesModal"/>
    </div>
</template>
<script>
import { getList as getOpenList, saveAttachmentApi, delAttachment as delGwfj } from "../api/common/gwfj";
import UploadGroup from "./UploadGroup"
import GwfjFilesListModal from "./GwfjFilesListModal"

export default {
    name: "GwfjUploadShow",
    components: {
        UploadGroup,
        GwfjFilesListModal
    },
    props: ["relationUnid", "moduleName", "bookmark", "type", "showUpload"],
    data() {
        return {
            gwfjList: []
        }
    },
    created() {
        this.reload()
    },
    methods:{
        handleUpload() {
            this.$refs.roup.show();
        },
        openFilesModal(item) {
            console.log(item)
            if (item.type == '依据文')
            {
                this.goYJWFile(item)
            }else
            {
                this.$refs.gwfjfilesModal.showFileList(item.unid)
            }
        },
        reload() {
            if (typeof(this.relationUnid) == "undefined")
            {
                return
            }
            const params = {
                ssgwUnid: this.relationUnid,
                type: this.type
            };
            getOpenList(params)
                .then((res) => {
                    console.log(res)
                if (res.code === 200) {
                    this.gwfjList = res.result.data
                }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        goYJWFile(e) {
            console.log(e);
            if (e.yjwModuleName == "swgl") {
                this.$router.push({
                path: `/swgl/swdj`,
                query: {
                    unid: e.yjwModuleUnid,
                },
                });
            } else if (e.yjwModuleName == "fwgl") {
                this.$router.push({
                path: `/fwgl/fwng`,
                query: {
                    unid: e.yjwModuleUnid,
                },
                });
            } else {
                this.$router.push({
                path: `/spsx/qbglinfo`,
                query: {
                    unid: e.yjwModuleUnid,
                },
                });
            }
            },
    }
}
</script>